package com.joe.test;

import java.util.HashMap;
import java.util.HashSet;

public class CompareByHash {
	
	public static HashMap getHashMap(int size){
		HashMap map = new HashMap();
		for(int i=0;i<size;i++){
			map.put("t"+i, "");
		}
		return map;
	}
	
	public static void compare(){
		int size = 10000000;
		long start = System.currentTimeMillis();
		HashMap map = getHashMap(size);
		long end = System.currentTimeMillis();
		System.out.println("getHashMap cost:"+(end-start)+" ms.");
		for(int i=0,s = size+10;i<s;i++){
			if(map.get("t"+i)==null){
				System.out.println("t"+i+" is not in the map!");
			}
		}
		long last = System.currentTimeMillis();
		System.out.println("compare hashMap cost:"+(last-end)+" ms.");
	}
	
	public static HashSet getHashSet(int size){
		HashSet set = new HashSet();
		for(int i=0;i<size;i++){
			set.add("t"+i);
		}
		return set;
	}
	public static void compareHashSet(){
		int size = 10000000;
		long start = System.currentTimeMillis();
		HashSet set = getHashSet(size);
		long end = System.currentTimeMillis();
		System.out.println("getHashSet cost:"+(end-start)+" ms.");
		for(int i=0,s = size+10;i<s;i++){
			if(!set.contains("t"+i)){
				System.out.println("t"+i+" is not in the set!");
			}
		}
		long last = System.currentTimeMillis();
		System.out.println("compare hashSet cost:"+(last-end)+" ms.");
	}
	
	/**
	 * @param args
	 * VM arguments: -Xms128M -Xmx1024M
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
//		HashMap map = new HashMap();
//		map.put("t1", "");
//		System.out.println(map.get("t").toString().length());
		compare();
		compareHashSet();
	}

}
